package com.umanji.enterprise.domain;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinTable;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.Future;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import javax.validation.constraints.Size;

import org.springframework.core.style.ToStringCreator;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.format.annotation.NumberFormat;
import org.springframework.format.annotation.NumberFormat.Style;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import com.umanji.building.domain.Buildings;
import com.umanji.generic.entity.UUIDEntity;
import com.umanji.image.domain.Images;

import org.apache.commons.collections.FactoryUtils;
import org.apache.commons.collections.list.LazyList;

@Entity
@Table(name="umanji_enterprise")
public class Enterprises extends UUIDEntity<Enterprises> {

	@ManyToOne
	@JoinColumn(name="BUILDING_ID", insertable=true, updatable=true)
	private Buildings building;

	private String enterpriseSort;		// 업체 종류

	private String businessSort;		// 업체 분류

	private String enterpriseName;		// 상호명

	private Integer enterpriseFloor;	// 층수

	private String phoneNumber;			// 대표 전화

	private String homePageURL;			// 홈페이지

    @OneToMany(cascade=CascadeType.ALL)
    @JoinTable(
            name="EnterpriseImages",
            joinColumns = @JoinColumn( name="enterprise_id"),
            inverseJoinColumns = @JoinColumn( name="image_id")
    )
	private Collection<Images> enterpriseImage;		// 업체 이미지

	@Transient
	private CommonsMultipartFile enterpriseImageFileData;

	private Boolean businessHoursEnable;		// 24 시간 영업 유무
	
    @OneToMany(cascade=CascadeType.ALL)
    @JoinTable(
            name="EnterpriseBusinessHourImages",
            joinColumns = @JoinColumn( name="enterprise_id"),
            inverseJoinColumns = @JoinColumn( name="image_id")
    )
	private Collection<Images> businessHoursImage;	// 영업 시간 이미지

	@Transient
	private CommonsMultipartFile businessHoursImageFileData;

	private String representativeItems;		// 대표 품목

    @ManyToMany(targetEntity=ServiceItems.class, cascade=CascadeType.ALL )
    @JoinTable(
        name="ENTERPRISES_SERVICEITEMS",
        joinColumns = { @JoinColumn(name="ENTERPRISE_ID") },
        inverseJoinColumns = { @JoinColumn(name="SERVICEITEM_ID") }, 
        uniqueConstraints = {
            @UniqueConstraint(columnNames = { "ENTERPRISE_ID", "SERVICEITEM_ID" } )
        }
    )
    private List<ServiceItems> serviceItems = LazyList.decorate(new ArrayList<ServiceItems>(), FactoryUtils.instantiateFactory(Enterprises.class));
    
	private Boolean breastFeeding;		// 모유 수유실

	private Boolean parkingEnable;		// 주차 유무

	private Boolean batretEnable;		// 밧렛 유무

	private Integer parkingNumber = new Integer("0");		// 주차 유무

	private Integer targetUse = new Integer("0");		// 이용 대상

	private Date regDate;	// 생성일

    public Enterprises() {
    	serviceItems = new ArrayList<ServiceItems>();
    }

	public void setBusinessHoursEnable(Boolean businessHoursEnable) {
		this.businessHoursEnable = businessHoursEnable;
	}

	public Boolean getBusinessHoursEnable() {
		return businessHoursEnable;
	}

    public List<ServiceItems> getServiceItems() {
        return serviceItems;
    }

	public String getEnterpriseSort() {
		return enterpriseSort;
	}

	public void setEnterpriseSort(String enterpriseSort) {
		this.enterpriseSort = enterpriseSort;
	}

	public String getBusinessSort() {
		return businessSort;
	}

	public void setBusinessSort(String businessSort) {
		this.businessSort = businessSort;
	}

	public String getEnterpriseName() {
		return enterpriseName;
	}

	public void setEnterpriseName(String enterpriseName) {
		this.enterpriseName = enterpriseName;
	}

	public Integer getEnterpriseFloor() {
		return enterpriseFloor;
	}

	public void setEnterpriseFloor(Integer enterpriseFloor) {
		this.enterpriseFloor = enterpriseFloor;
	}

	public String getPhoneNumber() {
		return phoneNumber;
	}

	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	public String getHomePageURL() {
		return homePageURL;
	}

	public void setHomePageURL(String homePageURL) {
		this.homePageURL = homePageURL;
	}

	public Boolean getBreastFeeding() {
		return breastFeeding;
	}

	public void setBreastFeeding(Boolean breastFeeding) {
		this.breastFeeding = breastFeeding;
	}

	public Boolean getParkingEnable() {
		return parkingEnable;
	}

	public void setParkingEnable(Boolean parkingEnable) {
		this.parkingEnable = parkingEnable;
	}

	public Integer getParkingNumber() {
		return parkingNumber;
	}

	public void setParkingNumber(Integer parkingNumber) {
		this.parkingNumber = parkingNumber;
	}

	public Integer getTargetUse() {
		return targetUse;
	}

	public void setTargetUse(Integer targetUse) {
		this.targetUse = targetUse;
	}

	public Date getRegDate() {
		return regDate;
	}

	public void setRegDate(Date regDate) {
		this.regDate = regDate;
	}

	public Buildings getBuilding() {
		return building;
	}

	public void setBuilding(Buildings building) {
		this.building = building;
	}

	public void setServiceItems(List<ServiceItems> serviceItems) {
		this.serviceItems = serviceItems;
	}

	public void setBatretEnable(Boolean batretEnable) {
		this.batretEnable = batretEnable;
	}

	public Boolean getBatretEnable() {
		return batretEnable;
	}

	public void setRepresentativeItems(String representativeItems) {
		this.representativeItems = representativeItems;
	}

	public String getRepresentativeItems() {
		return representativeItems;
	}

	public void setEnterpriseImage(Collection<Images> enterpriseImage) {
		this.enterpriseImage = enterpriseImage;
	}

	public Collection<Images> getEnterpriseImage() {
		return enterpriseImage;
	}

	public void setEnterpriseImageFileData(CommonsMultipartFile enterpriseImageFileData) {
		this.enterpriseImageFileData = enterpriseImageFileData;
	}

	public CommonsMultipartFile getEnterpriseImageFileData() {
		return enterpriseImageFileData;
	}

	public void setBusinessHoursImage(Collection<Images> businessHoursImage) {
		this.businessHoursImage = businessHoursImage;
	}

	public Collection<Images> getBusinessHoursImage() {
		return businessHoursImage;
	}

	public void setBusinessHoursImageFileData(CommonsMultipartFile businessHoursImageFileData) {
		this.businessHoursImageFileData = businessHoursImageFileData;
	}

	public CommonsMultipartFile getBusinessHoursImageFileData() {
		return businessHoursImageFileData;
	}
}